package GUI.Lisenting;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class D01 {
    public static void main(String[] args) {
        MyLis myLis = new MyLis();
        Frame frame = new Frame();
        Button button = new Button();
        //下面的括号里面需要的是ActionListener变量，上面要创建对象
        button.addActionListener(myLis);
        button.setSize(200,200);
        frame.add(button,BorderLayout.CENTER);
        frame.setBounds(500,600,600,500);
        frame.setBackground(Color.cyan);
        frame.pack();
        frame.setVisible(true);
        windowClose(frame);
    }
    private static void windowClose(Frame frame){
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }



}
//这下面就是事件监听!!!
class MyLis implements ActionListener{
    int i=0;
    @Override
    public void actionPerformed(ActionEvent e) {
        //这里面写要产生的事件!
        if(i%2==0) {
            System.out.println("如果你也能和我一样?");
            i++;
            return;
        }
        if(i%2==1) {
            System.out.println("泰裤辣!");
            i++;
        }
    }
}